﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Trangchu : System.Web.UI.Page
{
    Hoa h = new Hoa();
    protected void Page_Load(object sender, EventArgs e)
    {
        FrmHoaCuoi.DataSource = h.Load_HoaCuoi();
        FrmHoaCuoi.DataBind();

        FrmHoaTY.DataSource = h.Load_HoaTY();
        FrmHoaTY.DataBind();

        FrmHoaMungSN.DataSource = h.Load_HoaMSNhat();
        FrmHoaMungSN.DataBind();

        FrmHoachumung.DataSource = h.Load_HoaCHucmung();
        FrmHoachumung.DataBind();

        FrmHoaBo.DataSource = h.Load_HoaBo();
        FrmHoaBo.DataBind();

        FrmHoaGio.DataSource = h.Load_Gio();
        FrmHoaGio.DataBind();

        FrmHoaTrongHop.DataSource = h.Load_HoaTrongHop();
        FrmHoaTrongHop.DataBind();

        FrmHoaLang.DataSource = h.Load_Hoalang();
        FrmHoaLang.DataBind();
    }
    DataTable tbl = new DataTable();
    protected void FrmHoaCuoi_ItemCommand(object sender, FormViewCommandEventArgs e)
    {
        if (e.CommandName == "chon")
        {
            string Mahoa = e.CommandArgument.ToString();
            Session["Mahoa"] = Mahoa;

            string Maloai = FrmHoaCuoi.DataKey[0].ToString();
            Session["Maloai"] = Maloai;
            Response.Redirect("CThoa.aspx");
        }
        if (e.CommandName == "mua")
        {
            if (Session["hoa"] == null)
            {
                tbl.Columns.Add("mahoa", typeof(string));
                tbl.Columns.Add("tenhoa", typeof(string));
                tbl.Columns.Add("giahoa", typeof(float));
                tbl.Columns.Add("soluong", typeof(int));
                tbl.Columns.Add("thanhtien", typeof(float), "soluong*giahoa");
                Session["hoa"] = tbl;
            }
            tbl = (DataTable)Session["hoa"];
            Label tenhoa = (Label)FrmHoaCuoi.FindControl("lblhoacuoi");
            Label gia = (Label)FrmHoaCuoi.FindControl("lblGiaHoa");
            tbl.Rows.Add(e.CommandArgument.ToString(), tenhoa.Text, gia.Text, 1);
            int count = tbl.Rows.Count;
            Session["hoa"] = tbl;
            Response.Redirect(Request.Path);
        }
    }

    protected void FrmHoaTY_ItemCommand(object sender, FormViewCommandEventArgs e)
    {
        if (e.CommandName == "chon")
        {
            string Mahoa = e.CommandArgument.ToString();
            Session["Mahoa"] = Mahoa;

            string Maloai = FrmHoaTY.DataKey[0].ToString();
            Session["Maloai"] = Maloai;
            Response.Redirect("CThoa.aspx");
        }
            if (e.CommandName == "mua")
            {
                if (Session["hoa"] == null)
                {
                    tbl.Columns.Add("mahoa", typeof(string));
                    tbl.Columns.Add("tenhoa", typeof(string));
                    tbl.Columns.Add("giahoa", typeof(float));
                    tbl.Columns.Add("soluong", typeof(int));
                    tbl.Columns.Add("thanhtien", typeof(float), "soluong*giahoa");
                    Session["hoa"] = tbl;
                }
                tbl = (DataTable)Session["hoa"];
                Label tenhoa = (Label)FrmHoaTY.FindControl("lblty");
                Label gia = (Label)FrmHoaTY.FindControl("lblGiaHoa");
                tbl.Rows.Add(e.CommandArgument.ToString(), tenhoa.Text, gia.Text, 1);
                int count = tbl.Rows.Count;
                Session["hoa"] = tbl;
                Response.Redirect(Request.Path);
            }
    }
    protected void FrmHoaMungSN_ItemCommand(object sender, FormViewCommandEventArgs e)
    {
        if (e.CommandName == "chon")
        {
            string Mahoa = e.CommandArgument.ToString();
            Session["Mahoa"] = Mahoa;

            string Maloai = FrmHoaMungSN.DataKey[0].ToString();
            Session["Maloai"] = Maloai;
            Response.Redirect("CThoa.aspx");
        }
        if (e.CommandName == "mua")
        {
            if (Session["hoa"] == null)
            {
                tbl.Columns.Add("mahoa", typeof(string));
                tbl.Columns.Add("tenhoa", typeof(string));
                tbl.Columns.Add("giahoa", typeof(float));
                tbl.Columns.Add("soluong", typeof(int));
                tbl.Columns.Add("thanhtien", typeof(float), "soluong*giahoa");
                Session["hoa"] = tbl;
            }
            tbl = (DataTable)Session["hoa"];
            Label tenhoa = (Label)FrmHoaMungSN.FindControl("lblMSN");
            Label gia = (Label)FrmHoaMungSN.FindControl("lblGiaHoa");
            tbl.Rows.Add(e.CommandArgument.ToString(), tenhoa.Text, gia.Text, 1);
            int count = tbl.Rows.Count;
            Session["hoa"] = tbl;
            Response.Redirect(Request.Path);
        }
    }
    protected void FrmHoachumung_ItemCommand(object sender, FormViewCommandEventArgs e)
    {
        if (e.CommandName == "chon")
        {
            string Mahoa = e.CommandArgument.ToString();
            Session["Mahoa"] = Mahoa;

            string Maloai = FrmHoachumung.DataKey[0].ToString();
            Session["Maloai"] = Maloai;
            Response.Redirect("CThoa.aspx");
        }
        if (e.CommandName == "mua")
        {
            if (Session["hoa"] == null)
            {
                tbl.Columns.Add("mahoa", typeof(string));
                tbl.Columns.Add("tenhoa", typeof(string));
                tbl.Columns.Add("giahoa", typeof(float));
                tbl.Columns.Add("soluong", typeof(int));
                tbl.Columns.Add("thanhtien", typeof(float), "soluong*giahoa");
                Session["hoa"] = tbl;
            }
            tbl = (DataTable)Session["hoa"];
            Label tenhoa = (Label)FrmHoachumung.FindControl("lblhoachucmung");
            Label gia = (Label)FrmHoachumung.FindControl("lblGiaHoa");
            tbl.Rows.Add(e.CommandArgument.ToString(), tenhoa.Text, gia.Text, 1);
            int count = tbl.Rows.Count;
            Session["hoa"] = tbl;
            Response.Redirect(Request.Path);
        }
    }
    protected void FrmHoaBo_ItemCommand(object sender, FormViewCommandEventArgs e)
    {
        if (e.CommandName == "chon")
        {
            string Mahoa = e.CommandArgument.ToString();
            Session["Mahoa"] = Mahoa;

            string Maloai = FrmHoaBo.DataKey[0].ToString();
            Session["Maloai"] = Maloai;
            Response.Redirect("CThoa.aspx");
        }
        if (e.CommandName == "mua")
        {
            if (Session["hoa"] == null)
            {
                tbl.Columns.Add("mahoa", typeof(string));
                tbl.Columns.Add("tenhoa", typeof(string));
                tbl.Columns.Add("giahoa", typeof(float));
                tbl.Columns.Add("soluong", typeof(int));
                tbl.Columns.Add("thanhtien", typeof(float), "soluong*giahoa");
                Session["hoa"] = tbl;
            }
            tbl = (DataTable)Session["hoa"];
            Label tenhoa = (Label)FrmHoaBo.FindControl("lblbo");
            Label gia = (Label)FrmHoaBo.FindControl("lblGiaHoa");
            tbl.Rows.Add(e.CommandArgument.ToString(), tenhoa.Text, gia.Text, 1);
            int count = tbl.Rows.Count;
            Session["hoa"] = tbl;
            Response.Redirect(Request.Path);
        }
    }
    protected void FrmHoaGio_ItemCommand(object sender, FormViewCommandEventArgs e)
    {
        if (e.CommandName == "chon")
        {
            string Mahoa = e.CommandArgument.ToString();
            Session["Mahoa"] = Mahoa;

            string Maloai = FrmHoaGio.DataKey[0].ToString();
            Session["Maloai"] = Maloai;
            Response.Redirect("CThoa.aspx");
        }
        if (e.CommandName == "mua")
        {
            if (Session["hoa"] == null)
            {
                tbl.Columns.Add("mahoa", typeof(string));
                tbl.Columns.Add("tenhoa", typeof(string));
                tbl.Columns.Add("giahoa", typeof(float));
                tbl.Columns.Add("soluong", typeof(int));
                tbl.Columns.Add("thanhtien", typeof(float), "soluong*giahoa");
                Session["hoa"] = tbl;
            }
            tbl = (DataTable)Session["hoa"];
            Label tenhoa = (Label)FrmHoaGio.FindControl("lblgio");
            Label gia = (Label)FrmHoaGio.FindControl("lblGiaHoa");
            tbl.Rows.Add(e.CommandArgument.ToString(), tenhoa.Text, gia.Text, 1);
            int count = tbl.Rows.Count;
            Session["hoa"] = tbl;
            Response.Redirect(Request.Path);
        }
    }
    protected void FrmHoaTrongHop_ItemCommand(object sender, FormViewCommandEventArgs e)
    {
        if (e.CommandName == "chon")
        {
            string Mahoa = e.CommandArgument.ToString();
            Session["Mahoa"] = Mahoa;

            string Maloai = FrmHoaTrongHop.DataKey[0].ToString();
            Session["Maloai"] = Maloai;
            Response.Redirect("CThoa.aspx");
        }
        if (e.CommandName == "mua")
        {
            if (Session["hoa"] == null)
            {
                tbl.Columns.Add("mahoa", typeof(string));
                tbl.Columns.Add("tenhoa", typeof(string));
                tbl.Columns.Add("giahoa", typeof(float));
                tbl.Columns.Add("soluong", typeof(int));
                tbl.Columns.Add("thanhtien", typeof(float), "soluong*giahoa");
                Session["hoa"] = tbl;
            }
            tbl = (DataTable)Session["hoa"];
            Label tenhoa = (Label)FrmHoaTrongHop.FindControl("lblhoatronghop");
            Label gia = (Label)FrmHoaTrongHop.FindControl("lblGiaHoa");
            tbl.Rows.Add(e.CommandArgument.ToString(), tenhoa.Text, gia.Text, 1);
            int count = tbl.Rows.Count;
            Session["hoa"] = tbl;
            Response.Redirect(Request.Path);
        }
    }
    protected void FrmHoaLang_ItemCommand(object sender, FormViewCommandEventArgs e)
    {
        if (e.CommandName == "chon")
        {
            string Mahoa = e.CommandArgument.ToString();
            Session["Mahoa"] = Mahoa;

            string Maloai = FrmHoaLang.DataKey[0].ToString();
            Session["Maloai"] = Maloai;
            Response.Redirect("CThoa.aspx");
        }
        if (e.CommandName == "mua")
        {
            if (Session["hoa"] == null)
            {
                tbl.Columns.Add("mahoa", typeof(string));
                tbl.Columns.Add("tenhoa", typeof(string));
                tbl.Columns.Add("giahoa", typeof(float));
                tbl.Columns.Add("soluong", typeof(int));
                tbl.Columns.Add("thanhtien", typeof(float), "soluong*giahoa");
                Session["hoa"] = tbl;
            }
            tbl = (DataTable)Session["hoa"];
            Label tenhoa = (Label)FrmHoaLang.FindControl("lblhoalang");
            Label gia = (Label)FrmHoaLang.FindControl("lblGiaHoa");
            tbl.Rows.Add(e.CommandArgument.ToString(), tenhoa.Text, gia.Text, 1);
            int count = tbl.Rows.Count;
            Session["hoa"] = tbl;
            Response.Redirect(Request.Path);
        }
        
    }
    protected void FrmHoachumung_PageIndexChanging(object sender, FormViewPageEventArgs e)
    {

    }
    protected void FrmHoaBo_PageIndexChanging(object sender, FormViewPageEventArgs e)
    {

    }
}
